//
//  CYBaseCollectionViewController.m
//  CYTabBarViewController
//
//  Created by lc4y on 2017/12/4.
//  Copyright © 2017年 weiwang. All rights reserved.
//

#import "CYBaseCollectionViewController.h"

@interface CYBaseCollectionViewController () 

@end

@implementation CYBaseCollectionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self configCollectionView];
}

- (void)cy_configLayoutSubViews {
    
    if( [_cy_collectionView superview] ) {
        [_cy_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            if([self isKindOfClass:NSClassFromString(@"CYBottomViewController")]) {
                make.left.top.right.mas_equalTo(0);
                make.height.mas_equalTo(self.cy_tabBarController.titleView.cy_height);
            } else {
                make.edges.mas_equalTo(0);
            }
        }];
    }
}

- (void)setContentArray:(NSArray *)contentArray {
    _cy_dataArray = [contentArray copy];
    [self setCy_currentIndex:0];
    [self cy_calcItemSpace];  //计算间距
    [_cy_collectionView reloadData];
}

- (void)cy_calcItemSpace{}

- (CGFloat)stringWidth:(NSString *)string {
    CGFloat width = [string boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 50) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:self.cy_tabBarController.titleView.cy_titleFont} context:nil].size.width;
    return width;
}

-(void)configCollectionView {
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    flowLayout.minimumLineSpacing = 0;
    flowLayout.minimumInteritemSpacing = 0;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    _cy_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
    _cy_collectionView.backgroundColor = [UIColor clearColor];
    _cy_collectionView.showsVerticalScrollIndicator = NO;
    _cy_collectionView.showsHorizontalScrollIndicator = NO;
    _cy_collectionView.bounces = NO;
    _cy_collectionView.dataSource = self;
    _cy_collectionView.delegate = self;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _cy_dataArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *collectionCell = [collectionView dequeueReusableCellWithReuseIdentifier:CYCollectionCell forIndexPath:indexPath];
    [self cy_refreshCollectionCell:collectionCell indexPath:indexPath];
    return collectionCell;
}

- (void)cy_refreshCollectionCell:(UICollectionViewCell *)collectionCell indexPath:(NSIndexPath *)indexPath {
}

@end
